<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%--
  Created by IntelliJ IDEA.
  User: Lemon
  Date: 2020/6/18
  Time: 9:25
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>

<head>
    <title>转交页面</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui/css/layui.css">
    <style type="text/css">
        .layui-form-item{ margin-top: 45px; margin-left:60px;}
    </style>
</head>
<body>

<form class="layui-form">
    <div class="layui-form-item" >
        <label class="layui-form-label">客户经理：</label>
        <div class="layui-input-inline" style="width: 320px;">
            <select name="new_manager_id" lay-search lay-verify="required">
                <option value="">请选择</option>
                <c:forEach items="${service}" var="user">
                    <option value="${user.user_id}">${user.user_account}</option>
                </c:forEach>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">转交原因：</label>
        <div class="layui-input-inline">
            <textarea name="reason" style="width: 500px; height:200px;" placeholder="请输入转交的原因" lay-verify="required" class="layui-textarea" ></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block" >
            <button type="reset" class="layui-btn layui-btn-warm" style="margin-left: 150px;">重置</button>
            <button type="button" lay-submit lay-filter="transfer" class="layui-btn">转交</button>
        </div>
    </div>
    <input type="hidden" name="old_manager_id" value="${serviceSelf.creater}"/>
    <input type="hidden" name="service_id" value="${service_id}"/>
</form>

</body>
<script src="${pageContext.request.contextPath}/static/layui/layui.js"></script>
<script>
    layui.use(['form','layer','jquery'], function() {
        var form = layui.form;
        var layer = layui.layer;
        var $ = layui.$;

        form.on("submit(transfer)",function (data) {
            //发起异步请求，新增 data.field 表单数据
            $.post("${pageContext.request.contextPath}/service/insertWithHandler?new_manager_id="+data.field.new_manager_id+"&service_id="+data.field.service_id,data.field,function (result) {
                if (result.code==0){
                    //刷新父窗口的表格 parent 父窗口对象
                    parent.layui.table.reload("serviceTable",{
                        page:{
                            curr:1
                        }
                    })
                    //关闭本窗口
                    //当你在iframe页面关闭自身时
                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    parent.layer.close(index); //再执行关闭
                }
                else {
                    layer.msg("转交失败");
                }
            },"json");
            return false;//阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
    });
</script>
</html>